package routers

import (
	"github.com/kataras/iris/core/router"
	"github.com/kataras/iris"
)

func TestRouter(api router.Party){

	// 这里可以加入中间件，比如登录判断，执行顺序是自上而下
	// api.Use(LoginMiddleware().Permission)

	//api.Get("/", func(ctx iris.Context) {
	//	ctx.Text("this is get request")
	//})

	api.Post("/", func(ctx iris.Context) {
		ctx.Text("this is post request")
	})

	api.Put("/", func(ctx iris.Context) {
		ctx.Text("this is put request")
	})

	api.Delete("/", func(ctx iris.Context) {
		ctx.Text("this is delete request")
	})

	// 获取路由参数
	api.Get("/{name:string}", func(ctx iris.Context) {
		// ctx.Params() 只适合 获取路由上的参数
		name := ctx.Params().GetTrim("name")
		ctx.Text("this is get request ,name = " + name)
	})

	// 获取 url 问号后面的参数
	api.Get("/", func(ctx iris.Context) {
		key := ctx.URLParamTrim("key")
		ctx.Text("this is get request ,key = " + key)
	})
}
